package com.hngy.xpq.uploadservice;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.Toast;

import java.util.List;

public class MainActivity extends AppCompatActivity {

    int Max = 100;
    int Min = 0;
    final int TIME_GAS = 0x11;
    // 控件
    ProgressBar uploadProgress;
    Button upload;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        progressBar();
    }

    private void progressBar() {
        upload = (Button) findViewById(R.id.upload);
        uploadProgress = (ProgressBar) findViewById(R.id.uploadProgress);
        uploadProgress.setMax(Max);

        upload.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                handler.sendEmptyMessage(TIME_GAS);
            }
        });
    }

    /**
     * 进度条显示
     */
    Handler handler = new Handler(){
        @Override
        public void handleMessage(@NonNull Message msg) {
            if (Min < Max) {
                Min ++;
                uploadProgress.setProgress(Min);
                handler.sendEmptyMessageDelayed(TIME_GAS,10);
            } else {
                Toast.makeText(MainActivity.this, "OK", Toast.LENGTH_SHORT).show();
            }
        }
    };
}